import { setStorageItem, getStorageItem, removeStorageItem } from './storage';

export type IUserInfo = {
  id: string;
  name: string;
};

export const userInfoStorageKey = 'userinfo';

export const getUserInfo = () => {
  try {
    return JSON.parse(getStorageItem(userInfoStorageKey)) as IUserInfo;
  } catch (e) {
    console.warn(e);
  }
};

export const setUserInfo = (value: IUserInfo) => {
  try {
    setStorageItem(userInfoStorageKey, JSON.stringify(value));
  } catch (e) {
    console.warn(e);
  }
};

export const removeUserInfo = () => removeStorageItem(userInfoStorageKey);
